package com.ajk.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ajk.server.dao.TestAnswerItemMapper;
import com.ajk.server.model.TestAnswerItem;
import com.ajk.server.model.query.TestAnswerItemQuery;
import com.ajk.server.service.TestAnswerItemService;

/**
 * 答案选项  <br>
 * t_test_answer_item <br>
 * v1.0 2016-05-01
 */
 @Service
 public class TestAnswerItemServiceImpl implements TestAnswerItemService {
	
	private static final Logger logger = LoggerFactory.getLogger(TestAnswerItemServiceImpl.class);
	
	@Autowired
	private TestAnswerItemMapper testAnswerItemMapper;
	
	/**
 	*根据ID删除 答案选项
 	*/
 	@Override
 	public Integer deleteTestAnswerItemById(Integer id){
 		return testAnswerItemMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 答案选项
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertTestAnswerItem(List<? extends TestAnswerItem> testAnswerItems){
		Integer count = testAnswerItemMapper.batchInsert(testAnswerItems);
		return count;
 	}
 	/**
 	*新增 答案选项
 	*/
 	@Override
 	@Transactional
 	public Integer insertTestAnswerItem(TestAnswerItem domain){
		Integer id = testAnswerItemMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 答案选项
 	*/
 	@Override
 	@Transactional
 	public Integer updateTestAnswerItem(TestAnswerItem domain){
		Integer count = testAnswerItemMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 答案选项
 	*/
 	public TestAnswerItem findTestAnswerItemById(Integer id){
 		TestAnswerItem result = testAnswerItemMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 答案选项
 	*/
	public List<TestAnswerItem> findTestAnswerItemByQuery(TestAnswerItemQuery query){
		query.dealWith();
		List<TestAnswerItem> result = testAnswerItemMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (TestAnswerItem testAnswerItem : result) {
				testAnswerItem.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countTestAnswerItemByQuery(TestAnswerItemQuery query){
 		query.dealWith();
 		Integer result = testAnswerItemMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<TestAnswerItem> findTestAnswerItemByIds(List<Integer> ids){
 		List<TestAnswerItem> result = testAnswerItemMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (TestAnswerItem testAnswerItem : result) {
				testAnswerItem.dealWith();
			}
		}
		return result;
 	}
 	
}	